//let URL = "http://www.baidu.com?name=张三&age=25&sex=男&wife=小红"
/**function getUrlParams(url) {
    // 通过 ? 分割获取后面的参数字符串
    let urlStr = url.split('?')[1]
    // 创建空对象存储参数
	let obj = {};
    // 再通过 & 将每一个参数单独分割出来
	let paramsArr = urlStr.split('&')
	for(let i = 0,len = paramsArr.length;i < len;i++){
        // 再通过 = 将每一个参数分割为 key:value 的形式
		let arr = paramsArr[i].split('=')
		obj[arr[0]] = arr[1];
	}
	return obj
}*/
//String.prototype.replaceAll=function(s1,s2){
//	return this.replace(new RegExp(s1,"gm"),s2)
//}
var baseUrl	="/techshine/"		        
				        

function getQueryString(key){
    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
    var result = window.location.search.substr(1).match(reg);
    return result?decodeURIComponent(result[2]):null;
} 
function openPage(url,name,width,height){
	if (!width) {
		var width = window.innerWidth;
        width = width*0.8+"px";
    }
    if (!height) {
        var height = window.innerHeight;
        height = height*0.8+"px";
    }
	layer.open({
	  type: 2, 
	  title: name,
	  area: [width,height],
	  content: url //这里content是一个普通的String
	}); 
}

function closePage(){
	//layer.close(layer.index); //它获取的始终是最新弹出的某个层，值是由layer内部动态递增计算的
	//当你在iframe页面关闭自身时
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	parent.layer.close(index); //再执行关闭
}

function echoEdit(data,formId){
	if(!formId) {
		formId = '#edit-form';
	}
	if(typeof(data) === 'undefined') {
		return false;
	}
	$(formId + ' input,textarea').each(function(i) {
		var $this = $(this);
		var nodeName = $this.prop('nodeName');
		if(nodeName === 'TEXTAREA') {
			$this.val(data[$this.prop('name')]);
		}else if(nodeName === 'INPUT') {
			if($this.prop('type') === 'radio') {
				if($this.filter(':visible').length === 1) {
					if($this.val() == data[$this.prop('name')]) {
						$this.prop('checked', true);
					}
				}
			} else if($this.prop('type') === 'checkbox') {
				if($this.filter(':visible').length === 1) {
					var val = data[$this.prop('name')];
					if($.isNotEmpty(val)) {
						var array = val.split(',');
						if($.inArray($this.val(), array) > -1) {
							$this.prop('checked', true);
						}
					}
				}
			} else {
				$this.val(data[$this.prop('name')]);
			}
		}
	})
}
function initSel(id,url,name,form){
	$.ajax({
		type:"get",
		url:url,
		async:false,
		success:function(res){
			var htmlstr="";
			$.each(res.data, function(i,obj) {
				htmlstr+='<option value="'+obj.id+'">'+obj[name]+'</option>'
			});
			$("#"+id).html(htmlstr)
			form.render();
		}
	});
}
var nodshowd={
	'2400':{'1':'状态','3':'RGB','4':'继电器','5':'坐标'},
	'2500':{'1':'煤气浓度%','3':'气压/Kpa','4':'燃气累积量m^3'},
	'2600':{'1':'水位深度cm','4':'位移','3':'水浸状态'},
	'2700':{'1':'位移','3':'水压/Kpa','4':'用水累积量m^3'},
	'2800':{'0':'深度cm','1':'空气质量','3':'类别'},
	'2900':{'12':'温湿度','13':'光照度'},
	'3000':{'1':'状态'},
	'3100':{'1':'状态'}
}
function fullopen(n,m){
	var res=Math.random()*(m-n)+n;
	return res.toFixed(1);
}

function tonull(str){
	
	if(str==null){
		return '无'
	}else{ 
		return str
	}
}
function comm(nodid,comm,commkz){
	$.ajax({
		type:"get",
		url:"/hardware/project/comm",
		async:true,
		data:{
			nodid:nodid,
			comm:comm,
			commkz:commkz
		},
		success:function(res){
			if(res.status!=200){
				layer.msg(res.msg)
			}else{
				if(res.contrType=="2"){
					var id=res.ip.replaceAll(".","")+res.addr+res.msgattr
					$("#"+id).text(res.msg)
				}
			}
		}
	});
} 
function comm1(nodid,comm){
	if($("input:radio:checked").length==0){
		layer.msg("请先选择要控制的垃圾桶");
		return;
	}
	var ljtg=$("input:radio:checked").val();
	$.ajax({
		type:"get",
		url:"/hardware/project/comm",
		async:true,
		data:{
			nodid:nodid,
			comm:comm,
			commkz:ljtg
		},
		success:function(res){
			if(res.status!=200){
				layer.msg(res.msg)
			}else{
				if(res.contrType=="2"){
					var id=res.ip.replaceAll(".","")+res.addr+"a"
					$("#"+id).text(res.msg)
				}
			}
		}
	});
} 
